package com.bwie.controller;

import com.bwie.pojo.Type;
import com.bwie.service.TypeService;
import com.bwie.utils.Result;
import com.bwie.vo.PageInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author: TaoShiHao
 * @Date: 2025/5/24 10:28
 * @Description:
 **/
@RestController
@RequestMapping("/shop/type")
@Api(tags = "分类管理")
public class TypeController {

    @Autowired
    TypeService typeService;

    @PostMapping
    @ApiOperation(value = "添加产品分类")
    public Result addType(@RequestBody Type type){
        return typeService.addType(type);
    }
    @PostMapping("/addChildrenType")
    @ApiOperation(value = "添加产品子分类")
    public Result addChildrenType(@RequestBody Type type){
        return typeService.addType(type);
    }
    @DeleteMapping("/deleteType{typeId}")
    @ApiOperation(value = "根据ID删除商品分类")
    public Result deleteType(@PathVariable(name = "typeId")Integer typeId){
        return typeService.deleteType(typeId);
    }

    /**
     * 获取商品分类的树(表格)
     * @return
     */
    @GetMapping
    @ApiOperation(value = "获取商品分类的树(表格)")
    public Result getTypeTreeList(){
        return typeService.getTypeTreeList();
    }

    /**
     * 获取商品分类的树(下拉框)
     * @return
     */
    @PostMapping("/getTypeSelectTreeList")
    @ApiOperation(value = "获取商品分类的树(下拉框)")
    public Result getTypeSelectTreeList(){
        return typeService.getTypeSelectTreeList();
    }
    @PostMapping("/setTypeStatus/{typeId}/{typeStatus}")
    @ApiOperation(value = "显示或隐藏类型")
    public Result setTypeStatus(@PathVariable(name = "typeId") Integer typeId,@PathVariable(name = "typeStatus")Integer typeStatus){
        return typeService.setTypeStatus(typeId,typeStatus);
    }
    @PostMapping("/deleteTypeById/{typeId}")
    @ApiOperation(value = "删除分类")
    public Result deleteTypeById(@PathVariable(name = "typeId") Integer typeId){
        return typeService.deleteTypeById(typeId);
    }
    @PostMapping("/uploadFile")
    @ApiOperation(value = "上传图片")
    public Result uploadFile(@RequestPart(name = "file")MultipartFile file){
        return typeService.uploadFile(file);
    }
    @PostMapping("/updateType")
    @ApiOperation(value = "修改商品类型")
    public Result updateType(@RequestBody Type type){
        return typeService.updateType(type);
    }

}
